# http://10.216.11.12:8089/cis/showView.jsp
import re

import requests
def get_sanyaosu(id,cookie):
    url = f'{id}/cis/showView.jsp'
    HOST = id.strip("http://")
    headers = {

        "Cookie": f"JSESSIONID={cookie}",
        "Host": HOST,
        "Referer": "http://10.216.11.12:8089/cis/desktop.jsp",
        "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/138.0.0.0 Safari/537.36"
    }
    sanyaosu = []

    res = requests.get(url, headers=headers)

    # 医生代码
    match_ysdm = re.search(r"json\.ysdm\s*=\s*'([^']+)'", res.text)
    if match_ysdm:
        ysdm_code = match_ysdm.group(1)
        print("提取到的医生代码:", ysdm_code)
        sanyaosu.append(ysdm_code)
    else:
        print("未找到医生代码")
        return None

    # 科室代码
    math_ksdm = re.search(r"json\.ksdm\s*=\s*'([^']+)'", res.text)
    if math_ksdm:
        ksdm_code = math_ksdm.group(1)
        print("提取到的科室代码:", ksdm_code)
        sanyaosu.append(ksdm_code)
    else:
        print("未找到科室代码")
        return None

    # 假设 res.text 是包含目标内容的响应文本
    match = re.search(r"json\.hospitalcode\s*=\s*'([^']+)'", res.text)
    if match:
        hospital_code = match.group(1)
        print("提取到的机构码:", hospital_code)
        sanyaosu.append(hospital_code)
    else:
        print("未找到机构码")
        return None

    # 医生名称
    match = re.search(r"json\.ysmc\s*=\s*'([^']+)'", res.text)
    if match:
        ysmc_code = match.group(1)
        print("提取到的医生名称:", ysmc_code)
        sanyaosu.append(ysmc_code)
    else:
        print("未找到医生名称")
        return None

    return sanyaosu


if __name__ == '__main__':
    if __name__ == '__main__':
        ysdm,ksdm,jigou = get_sanyaosu("http://10.216.11.12:8089", "8F6F290B1CD9E0B151928FA63E898F0A")
        print(type(ysdm),type(ksdm),type(jigou))
        print(ysdm,ksdm,jigou)
        # get_jigou("http://10.166.140.210:8083", "F9B3A85983251ED68AD0FD992D37969D")